﻿@model WebApplication1.Models.LoginModel
@{
    ViewBag.Title = "Index";
}

<div class="div111">
    面向对象
    <input id="txtMsg" /><button type="button" id="btn" >发送</button>
    <table class="table table-hover">
        <tr>
            <td></td>
            <td></td>
        </tr>
    </table>
</div>



@section Scripts {
<script>
    var allMsgs = new Array();
     
    var chatmsg = {
        tasks: new Array(),
        msgs: new Array(),
        addmsg: function (msg) {
            var that = this;
            var rdm = Math.random();
            this.msgs.push({ "Id": rdm, "msg": msg, "state": 0 });
            this.tasks.push(setTimeout('chatmsg.sendMsg()', 3000));
        },
        init: function () {
            var that = this;
            
            $('#btn').click(function () {
                that.addmsg($('#txtMsg').val());
            })
        },
        sendMsg: function () {
            
            //console.log(this.msgs.join(','));
            $.each(this.msgs, function (index, item) {

                console.log(JSON.stringify(item));

            });

        }
    }
    chatmsg.init();


    var show = {
        btn: $('.div1'),
        init: function () {
            var that = this;
            alert(this);
            this.btn.click(function () {
                that.change();
                alert(this);
            })

        },
        change: function () {
            this.btn.css({ 'background': 'green' });

        }
    }
    //show.init();


</script>
}